﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogicLayer;

namespace logicunivesityinventorystore.Store
{
    public partial class ApproveAdjustmentVoucher : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void btn_Approve_Click(object sender, EventArgs e)
        {
            
            string approvedBy = "A0102955H";
            if (gvAdjDetails.Rows.Count > 0)
            {
                foreach (GridViewRow gvRow in gvAdjDetails.Rows)
                {
                    CheckBox chkBox = (CheckBox)gvRow.Cells[0].FindControl("chkItem");
                    if (chkBox.Checked)
                    {
                        LinkButton linkBtn = (LinkButton)gvRow.Cells[1].FindControl("link_VoucherID");
                        string voucherID = linkBtn.Text;
                        new AdjustmentVoucherFacade().UpdateAdjustmentVoucher(voucherID, "Approved", approvedBy);
                    }
                }
            }
            gvAdjDetails.DataBind();
        }

        protected void link_VoucherID_Click(object sender, EventArgs e)
        {
            LinkButton linkbtn = (LinkButton)gvAdjDetails.FindControl("link_VoucherID");
            //GridView2.DataSource = new AdjustmentVoucherFacade().FindAdjustmentVoucherDetailsByVoucherID(linkbtn.Text);
            //GridView2.DataBind();
            //GridView2.DataSource = new AdjustmentVoucherFacade().FindAdjustmentVoucherDetailsByVoucherID(linkbtn.CommandArgument.ToString());
            //GridView2.DataBind();
        }

        protected void gvAdjDetails_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            //if (e.CommandName == "Select")
            //{
            //    GridView2.DataSource = new AdjustmentVoucherFacade().FindAdjustmentVoucherDetailsByVoucherID(e.CommandArgument.ToString());
            //    GridView2.DataBind();
            //}
            //if (e.CommandName == "Select")
            //{
            //    GridView2.DataSource = new AdjustmentVoucherFacade().FindAdjustmentVoucherDetailsByVoucherID(e.CommandArgument.ToString());
            //    GridView2.DataBind();
                
            //}
        }

        protected void gvAdjDetails_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string VoucherID = (e.Row.FindControl("lbtnVoucherID") as LinkButton).Text;
                (e.Row.FindControl("lbtnVoucherID") as LinkButton).Attributes.Add("onClick", "ShowEditModal('VoucherDetails.aspx?VoucherID=" + VoucherID + "');");

            }
        }
    }
}